function GrenadeDamage takes nothing returns nothing
	local unit target = GetEnumUnit()
	//--
	if IsUnitEnemy(target , udg_TempPlayer) and IsUnitInRangeLoc(target , udg_TempLocation , udg_TempRadius) and not IsUnitType(target , UNIT_TYPE_STRUCTURE) and GetUnitState(target , UNIT_STATE_LIFE) > 0.0 then
		call UnitDamageTarget(udg_TempDamager , target , udg_TempDamage , true , false , ATTACK_TYPE_NORMAL, DAMAGE_TYPE_COLD , WEAPON_TYPE_METAL_MEDIUM_BASH)
	endif
	//--
	set target = null
endfunction

function GrenadeRoutine takes nothing returns nothing
	local timer grenadeTimer = GetExpiredTimer(  )
	local integer timerId = GetHandleId( grenadeTimer )
	local unit grenadeEffect = LoadUnitHandle(udg_HT , timerId , 3 )
	local location grenadeLocation = GetUnitLoc( grenadeEffect )
	local real dx = LoadReal( udg_HT , timerId , 4 )
	local real dy = LoadReal( udg_HT , timerId , 5 )
	local real process = LoadReal( udg_HT , timerId , 6 )
	local boolean end = false
	local unit explosionEffect = null
	//--
	//移動子彈
	if process < 100.0 then
		set process = process + 1.0
		call SaveReal( udg_HT , timerId , 6 , process )
		call SetUnitX( grenadeEffect , GetUnitX( grenadeEffect ) + dx )
		call SetUnitY( grenadeEffect , GetUnitY( grenadeEffect ) + dy )
		call SetUnitFlyHeight(grenadeEffect , -0.2 * process * process + 20.0 * process , 0.0)
	else
		set end = true
	endif
	if end then
		//造成傷害
		set udg_TempDamager = grenadeEffect
		set udg_TempPlayer = GetOwningPlayer(grenadeEffect)
		set udg_TempDamage = 500.0
		set udg_TempRadius = 300.0
		set udg_TempLocation = grenadeLocation
		set bj_wantDestroyGroup = true
		call ForGroupBJ(GetUnitsInRangeOfLocMatching(udg_TempRadius+70.0, udg_TempLocation , null) , function GrenadeDamage)
		set explosionEffect = CreateUnit(GetOwningPlayer(grenadeEffect) , 'e009' , GetLocationX(udg_TempLocation) , GetLocationY(udg_TempLocation) , GetRandomReal(0.0 , 360.0))
		call SetUnitX(explosionEffect , GetLocationX(udg_TempLocation))
		call SetUnitY(explosionEffect , GetLocationY(udg_TempLocation))
		//摧毀timer
		call PauseTimer( grenadeTimer )
		call FlushChildHashtable( udg_HT , timerId )
		call DestroyTimer( grenadeTimer )
		call KillUnit( grenadeEffect )
		call RemoveUnit( grenadeEffect )

	endif
	//--
	set grenadeTimer = null
	set grenadeEffect = null
	call RemoveLocation( grenadeLocation )
	set grenadeLocation = null
endfunction

function Trig_Grenade_Actions takes nothing returns nothing
	local unit thrower = GetTriggerUnit()
	local player throwerOwner = GetOwningPlayer(thrower)
	local location throwerLocation = GetUnitLoc(thrower)
	local location targetLocation = GetSpellTargetLoc()
	local real distance = DistanceBetweenPoints(throwerLocation , targetLocation)
	local real angle = AngleBetweenPoints(throwerLocation , targetLocation)
	local real timerInterval = 0.01
	local real topSpeed = 1000.0
	local real maxDistance = 1000.0
	local real adjustedSpeed = topSpeed * (distance / maxDistance)
	local real delta = adjustedSpeed * timerInterval
	local real dx = Cos(angle * bj_DEGTORAD) * delta
	local real dy = Sin(angle * bj_DEGTORAD) * delta
	local unit grenadeEffect = CreateUnit(throwerOwner , 'e007' , GetLocationX(throwerLocation) , GetLocationY(throwerLocation) , angle)
	local timer grenadeTimer = CreateTimer()
	local integer timerId = GetHandleId(grenadeTimer)
	//--
	call SetUnitX(grenadeEffect , GetLocationX(throwerLocation) + dx)
	call SetUnitY( grenadeEffect , GetLocationY( throwerLocation ) + dy )
	call UnitAddAbility(grenadeEffect , 'Arav')
	call SetUnitFlyHeight(grenadeEffect , 0.0 , 0.0)
	call SaveUnitHandle( udg_HT , timerId , 3 , grenadeEffect )
	call SaveReal( udg_HT , timerId , 4 , dx )
	call SaveReal( udg_HT , timerId , 5 , dy )
	call SaveReal( udg_HT , timerId , 6 , 0.0 )
	call TimerStart( grenadeTimer , timerInterval , true , function GrenadeRoutine )
endfunction

function Trig_Grenade_Conditions takes nothing returns boolean
	return GetSpellAbilityId() == 'A00Q'
endfunction

function InitTrig_Grenade takes nothing returns nothing
	set gg_trg_Grenade = CreateTrigger()
	call TriggerRegisterAnyUnitEventBJ(gg_trg_Grenade , EVENT_PLAYER_UNIT_SPELL_EFFECT)
	call TriggerAddCondition(gg_trg_Grenade , Condition(function Trig_Grenade_Conditions))
	call TriggerAddAction(gg_trg_Grenade , function Trig_Grenade_Actions)
endfunction